import instance from "@/http/index.js"


// 绑定上传者
export const bindUploadPersonAPI = (data) => {
  const { upload_person, file_url } = data
  return instance({
    url: "/file/bindUploadPerson",
    method: "post",
    data: {
      upload_person,
      file_url
    }
  })
}

// 更新下载量 
export const updateDownloadNumberAPI = (data) => {
  const { download_number, id } = data
  return instance({
    url: "/file/updateDownloadNumber",
    method: "post",
    data: {
      download_number,
      id
    }
  })
}

// 下载文件  根据 id 拿到文件 url
export const downloadFileAPI = (id) => {
  return instance({
    url: "/file/downloadFile",
    method: "post",
    // 接收二进制流
    responseType: 'blob',
    data: {
      id
    }
  })
}

// 获取文件列表
export const getFileListAPI = () => {
  return instance.get("/file/getFileList")
}

// 获取文件列表总数
export const getFileListCountAPI = () => {
  return instance.get("/file/getFileListCount")
}

// 文件模糊搜索
export const searchFileAPI = (data) => {
  const { file_name } = data
  return instance({
    url: "/file/searchFile",
    method: "post",
    data: {
      file_name
    }
  })
}

// 删除文件
export const deleteFileAPI = (data) => {
  const { id, file_name } = data
  return instance({
    url: "/file/deleteFile",
    method: "delete",
    data: {
      id,
      file_name
    }
  })
}

// 文件列表分页
export const getFileListByPagerAPI = (data) => {
  const { pager } = data
  return instance({
    url: "/file/getFileListByPager",
    method: "post",
    data: {
      pager
    }
  })
}

// 根据id获取文件信息
export const getFileByIdAPI = (data) => {
  const { id } = data
  return instance({
    url: "/file/getFileById",
    method: "post",
    data: {
      id
    }
  })
}